package com.ypf.delaycancelorder.controller;

import com.ypf.delaycancelorder.service.ex.InsertException;
import com.ypf.delaycancelorder.service.ex.ServiceException;
import com.ypf.delaycancelorder.service.ex.UpdateException;
import com.ypf.delaycancelorder.utils.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;

public class BaseController {
    public static final int OK=200;

    @ExceptionHandler({ServiceException.class})
    public JsonResult<Void> handleException(Throwable e){
        JsonResult<Void> result = new JsonResult<>(e);

        if (e instanceof InsertException){
            result.setState(4000);
            result.setMessage("插入订单失败");
        }else if(e instanceof UpdateException){
            result.setState(4001);
            result.setMessage("更新订单状态失败");
        }

        return result;
    }

}
